package com.five.controller;

import com.five.pojo.ClubActivity;
import com.five.pojo.PageBean;
import com.five.pojo.Result;
import com.five.pojo.ClubRegister;
import com.five.service.ClubActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lenovo
 */
@Tag(name = "社团活动接口")
@RestController
@RequestMapping("/clubActivity")
public class ClubActivityController {
    @Autowired
    ClubActivityService clubActivityService;
    //获取所有活动信息
    @Operation(summary = "获取所有活动信息")
    @GetMapping("/getAll")
    public Result getAll(){
        List<ClubActivity> list = clubActivityService.getAllActivity();
        return Result.success(list);
    }
    //分页
    @Operation(summary = "按条件查询分页")
    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                        String actName)
    {
        PageBean pageBean = clubActivityService.page(page , pageSize , actName);
        return Result.success(pageBean);
    }

    //报名活动
    @Operation(summary = "报名活动")
    @PostMapping("/add")
    public Result add(@RequestBody ClubRegister clubRegister){
        String sName = clubActivityService.findByName(clubRegister.getSName());
        if(sName == null){
            clubActivityService.addRegisterInfo(clubRegister);
        }else {
            return Result.error("您已经报名，请勿重复报名");
        }
        return Result.success();
    }

    //管理员：删除活动
    @Operation(summary = "删除活动")
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        clubActivityService.deleteById(id);
        return Result.success();
    }


}
